package com.miplus.ccrm.core.service.conf;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miplus.ccrm.common.JPubUtils;
import com.miplus.ccrm.core.controller.vo.conf.NamesResVo;
import com.miplus.ccrm.core.pojo.SysNames;
import com.miplus.ccrm.core.mapper.SysNamesMapper;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
* @author pc
* @description 针对表【sys_names】的数据库操作Service实现
* @createDate 2024-04-26 01:26:45
*/
@Service
public class SysNamesServiceImpl extends ServiceImpl<SysNamesMapper, SysNames>
    implements SysNamesService{
    @Override
    public  List<String> getNamesID(String tid,boolean isall)
    {
        //FOR TDSQL
        //List<SysNames> rlist=baseMapper.selectList(
        //        new QueryWrapper<SysNames>().eq("tid",tid)
        //);
        List<SysNames> rlist=baseMapper.namesSelect(tid,null);
        List<String> prlist=new LinkedList<>();
        if(rlist!=null){
            for(SysNames prem : rlist){
                if(isall) {
                    prlist.add(prem.getId());
                }
                else if(JPubUtils.IsEqual(prem.getAvailable(),"1")){
                    prlist.add(prem.getId());
                }
            }
        }
        return prlist;
    }

    @Override
    public List<String> getNamesID(String tid,String pid)
    {
        //FOR TDSQL
        //List<SysNames> rlist=baseMapper.selectList(
        //        new QueryWrapper<SysNames>()
        //                .eq("tid",tid)
         //               .eq("parentid",pid)
        //);
        List<SysNames> rlist=baseMapper.namesSelect(tid,pid);
        List<String> prlist=new LinkedList<>();
        if(rlist!=null){
            for(SysNames prem : rlist){
                prlist.add(prem.getId());
            }
        }
        return prlist;
    }

    @Override
    public String getNamesDsc(String tid,String id)
    {
        //FOR TDSQL
        //SysNames names=baseMapper.selectOne(
        //        new QueryWrapper<SysNames>()
         //               .eq("tid",tid)
         //               .eq("id",id)
        //);
        SysNames names=baseMapper.namesSelectOne(tid,id);
        if(names==null) return "";

        return names.getDsc();
    }

    @Override
    public List<NamesResVo> getSysNamesList(String tid)
    {
        return baseMapper.getSysNamesList(tid);
    }

    @Override
    public List<NamesResVo>  getSelectOptionBySql(String sql)
    {
        return baseMapper.getSelectOptionBySql(sql);
    }
}




